package com.example.beans;

import org.springframework.beans.factory.annotation.Autowired;

public class SelfInvocation {

    private SelfInvocation selfInvocation;

    // 注入SelfInvocation的代理对象
    @Autowired
    public void setSelfInvocation(SelfInvocation selfInvocation) {
        this.selfInvocation = selfInvocation;
    }

    public String doSomething() {
        System.out.println("doSomething被执行");
        if (selfInvocation != null) {
            // 通过代理对象来调用doOtherThings方法，使得doOtherThings方法的AOP通知生效
            return selfInvocation.doOtherThings();
        }
        return "doSomething的返回值";
    }

    public String doOtherThings() {
        System.out.println("doOtherThings被执行");
        return "doOtherThings的返回值";
    }
}
